package jdly.water.api.util;

import java.text.DecimalFormat;
import java.util.Date;

public class NumberUtil {

	/**
	 * TODO 四舍五入保留两位小数
	 * 
	 * @param number
	 * @return
	 */
	public static double format2Decimal(double number) {

		return Double.parseDouble(String.format("%.2f", number));
	}
	
	public static String format2DecimalStr(double number) {

		return String.format("%.2f", number);
	}

	/**
	 * 用0 补位
	 * @param count
	 * @param number
	 * @return
	 */
	public static String buling(int count,int number){
		String numberstr = number + "";
		if(numberstr.length()<count){
			for(int i = 0 ; i <(count - numberstr.length());i++){
				numberstr = "0"+numberstr;
			}
		}
		return numberstr;
	}
	
	public static String format2DecimalFiil(double number) {
		DecimalFormat decimalFormat = new DecimalFormat("#.##");
		return decimalFormat.format(number);
	}

	
	public static double keep2(double num){
		
		return Double.valueOf(String.format("%.2f", num));
	}
	
	public static double createDouble(double min, double max) {
		double num = 0;
		num = Math.random() * max + min;
		while (num > max || num < min) {
			num = Math.random() * max + min;
		}
		return keep2(num);
	}

	public static int createInt(int min, int max) {

		int num = 0;
		num = (int) (Math.random() * max + min);
		while (num > max || num < min) {
			num = (int) (Math.random() * max + min);
		}
		return num;

	}
	
	public synchronized static String createNumberStr(){
		String number = DateUtils.getDate("yyyyMMddHHmmss")+createInt(100000, 999999);
		return number;
	}
}
